Passed
Push — main ( 5dc5e5...0c937b )
by Andrii
02:33
created

expect-to-same-render.ts ➔ expectRender   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 10
c 0
b 0
f 0
rs 9.95
cc 1
1
import {renderToStaticMarkup} from "react-dom/server"
2
3
type RElement = Parameters<typeof renderToStaticMarkup>[0]
4
5
export default expectRender
6
7
function expectRender(
8
  ...elements: RElement[]
9
) {
10
  const input = toStatic(elements)
11
12
  return {
13
    toSame: (...expectations: RElement[]) => expect(input).toBe(toStatic(expectations)),
14
    not: {
15
      toSame: (...expectations: RElement[]) => expect(input).not.toBe(toStatic(expectations)),
16
    }
17
  }
18
}
19
20
function toStatic(els: RElement[]) {
21
  return els.map(renderToStaticMarkup).join("")
22
}